//
//  DetailActivityView.m
//  豆瓣HW
//
//  Created by dllo on 15/11/26.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "DetailActivityView.h"

@implementation DetailActivityView

+ (CGFloat)heightWithStr:(NSString *)str    // 封装
{
    CGRect frame = [str boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18.0] forKey:NSFontAttributeName] context:nil];
    return frame.size.height;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
#warning 自适应高度2 - 自适应label高度, 注意label宽度应与自适应指定的宽度相同
    //  CGRect frame = [self.label.text boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18.0] forKey:NSFontAttributeName] context:nil];
    
    // 当.语法 与 访问结构体成员的.混合时, 系统不识别会报错
    //    self.label.frame.size.width = frame.size.height;
    CGFloat height = [[self class] heightWithStr:self.labelPosition.text];      // 封装
    
    // 先保存label的坐标及宽度信息
    CGRect frameL = self.labelPosition.frame;
    //    frameL.size.height = frame.size.height;
    frameL.size.height = height;         // 封装
    self.labelPosition.frame = frameL;
    
    CGFloat height1 = [[self class] heightWithStr:self.lableActivityIntroduceDate.text];      // 封装
    
    // 先保存label的坐标及宽度信息
    CGRect frameL1 = self.lableActivityIntroduceDate.frame;
    //    frameL.size.height = frame.size.height;
    frameL1.size.height = height1;         // 封装
    self.lableActivityIntroduceDate.frame = frameL1;
    
}

- (void)dealloc
{
    [_labelTitle release];
    [_imageV release];
    [_labelTime release];
    [_labelPerson release];
    [_labelStyleName release];
    [_positionImageV release];
    [_labelPosition release];
    [_lableActivityIntroduceDate release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews
{
    self.backgroundColor = [UIColor whiteColor];
    
    self.contentSize = CGSizeMake(0, self.frame.size.height * 3);
    
    self.labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 350, 30)];
//    self.labelTitle.backgroundColor = [UIColor redColor];
    self.labelTitle.font = [UIFont systemFontOfSize:20.0];
    [self addSubview:self.labelTitle];
    [self.labelTitle release];
    
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.self.labelTitle.frame.origin.x, self.self.labelTitle.frame.origin.y + 30, 150, 200)];
    self.imageV .image = [UIImage imageNamed:@"picholder@2x.png"];
    [self addSubview:self.imageV ];
    [self.imageV  release];
    
    UIImageView *timeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.imageV .frame.origin.x + self.imageV .frame.size.width + 5  , self.labelTitle.frame.origin.y + 30, 30, 30)];
    timeImageV.image = [UIImage imageNamed:@"icon_date_blue@2x.png"];
    [self addSubview:timeImageV];
    
    self.labelTime = [[UILabel alloc] initWithFrame:CGRectMake(timeImageV.frame.origin.x + timeImageV.frame.size.width + 5, timeImageV.frame.origin.y, 150, 30)];
//    self.labelTime.backgroundColor = [UIColor redColor];
    self.labelTime.font = [UIFont systemFontOfSize:10.0];
    [self addSubview:self.labelTime];
    
    UIImageView *personImageV = [[UIImageView alloc] initWithFrame:CGRectMake(timeImageV.frame.origin.x  , timeImageV.frame.origin.y + 35, 30, 30)];
    personImageV.image = [UIImage imageNamed:@"icon_sponsor_blue@2x.png"];
    [self addSubview:personImageV];
    
    self.labelPerson = [[UILabel alloc] initWithFrame:CGRectMake(self.labelTime.frame.origin.x, personImageV.frame.origin.y, 150, 30)];
//    self.labelPerson.backgroundColor = [UIColor redColor];
    self.labelPerson.font = [UIFont systemFontOfSize:10.0];
    [self addSubview:self.labelPerson];
    
    UIImageView *styleImageV = [[UIImageView alloc] initWithFrame:CGRectMake(personImageV.frame.origin.x  , personImageV.frame.origin.y + 35, 30, 30)];
    styleImageV.image = [UIImage imageNamed:@"icon_catalog_blue@2x.png"];
    [self addSubview:styleImageV];
    
    UILabel *labelStyle = [[UILabel alloc] initWithFrame:CGRectMake(self.labelPerson.frame.origin.x, self.labelPerson.frame.origin.y + 35, 50, 30)];
    labelStyle.text = @"类型:";
    [self addSubview:labelStyle];
    
    self.labelStyleName = [[UILabel alloc] initWithFrame:CGRectMake(labelStyle.frame.origin.x + labelStyle.frame.size.width, labelStyle.frame.origin.y, 50, 30)];
//    self.labelStyleName.backgroundColor = [UIColor blackColor];
    self.labelStyleName.font = [UIFont systemFontOfSize:10.0];
    [self addSubview:self.labelStyleName];
    
    self.positionImageV = [[UIImageView alloc] initWithFrame:CGRectMake(styleImageV.frame.origin.x  , styleImageV.frame.origin.y + 35, 30, 30)];
    self.positionImageV.image = [UIImage imageNamed:@"icon_spot_blue@2x.png"];
    [self addSubview:self.positionImageV];
    
    self.labelPosition = [[UILabel alloc] initWithFrame:CGRectMake(labelStyle.frame.origin.x, labelStyle.frame.origin.y + 35, 160, 1000)];
//    self.labelPosition.backgroundColor = [UIColor blueColor];
    self.labelPosition.font = [UIFont systemFontOfSize:14.0];
        self.labelPosition.numberOfLines = 0;
    [self addSubview:self.labelPosition];
    
    UILabel *activityIntroduce = [[UILabel alloc] initWithFrame:CGRectMake(self.imageV.frame.origin.x, self.imageV.frame.origin.y  + self.imageV.frame.size.height + 10, 100, 30)];
    activityIntroduce.font = [UIFont systemFontOfSize:24.0];
    activityIntroduce.text = @"活动介绍";
    [self addSubview:activityIntroduce];
    
    self.lableActivityIntroduceDate = [[UILabel alloc] initWithFrame:CGRectMake(activityIntroduce.frame.origin.x, activityIntroduce.frame.origin.y + 30, 300, 1000)];
//    self.lableActivityIntroduceDate.backgroundColor = [UIColor purpleColor];
    self.lableActivityIntroduceDate.numberOfLines = 0;
    [self addSubview:self.lableActivityIntroduceDate];
    [_lableActivityIntroduceDate release];
    
}

@end
